package com.ibm.risk.irmp.workflow.client.flowable.api;

import com.ibm.risk.irmp.workflow.client.flowable.ApiClient;

import com.ibm.risk.irmp.workflow.client.flowable.model.CaseInstanceResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.DataResponsePlanItemInstanceResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.PlanItemInstanceQueryRequest;
import com.ibm.risk.irmp.workflow.client.flowable.model.PlanItemInstanceResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.RestActionRequest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;


@Component("com.ibm.risk.irmp.flowable.api.PlanItemInstancesApi")
public class PlanItemInstancesApi {
    private ApiClient apiClient;

    public PlanItemInstancesApi() {
        this(new ApiClient());
    }

    @Autowired
    public PlanItemInstancesApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /**
     * Get an plan item instance
     *
     * <p><b>200</b> - Indicates the plan item instance was found and returned.
     * <p><b>404</b> - Indicates the plan item instance was not found.
     * @param planItemInstanceId The planItemInstanceId parameter
     * @return PlanItemInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public PlanItemInstanceResponse getPlanItemInstance(String planItemInstanceId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'planItemInstanceId' is set
        if (planItemInstanceId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'planItemInstanceId' when calling getPlanItemInstance");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("planItemInstanceId", planItemInstanceId);
        String path = UriComponentsBuilder.fromPath("/cmmn-runtime/plan-item-instances/{planItemInstanceId}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<PlanItemInstanceResponse> returnType = new ParameterizedTypeReference<PlanItemInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * List of plan item instances
     *
     * <p><b>200</b> - Indicates request was successful and the executions are returned
     * <p><b>400</b> - Indicates a parameter was passed in the wrong format . The status-message contains additional information.
     * @param id Only return models with the given version.
     * @param caseDefinitionId Only return plan item instances with the given case definition id.
     * @param caseInstanceId Only return plan item instances which are part of the case instance with the given id.
     * @param stageInstanceId Only return plan item instances which are part of the given stage instance.
     * @param planItemDefinitionId Only return plan item instances which have the given plan item definition id.
     * @param planItemDefinitionType Only return plan item instances which have the given plan item definition type.
     * @param planItemDefinitionTypes Only return plan item instances which have any of the given plan item definition types. Comma-separated string e.g. humantask, stage
     * @param state Only return plan item instances which have the given state.
     * @param name Only return plan item instances which have the given name.
     * @param elementId Only return plan item instances which have the given element id.
     * @param referenceId Only return plan item instances which have the given reference id.
     * @param referenceType Only return plan item instances which have the given reference type.
     * @param createdBefore Only return plan item instances which are created before the given date.
     * @param createdAfter Only return plan item instances which are created after the given date.
     * @param startUserId Only return plan item instances which are started by the given user id.
     * @param tenantId Only return plan item instances with the given tenantId.
     * @param withoutTenantId If true, only returns plan item instances without a tenantId set. If false, the withoutTenantId parameter is ignored.
     * @param sort Property to sort on, to be used together with the order.
     * @return DataResponsePlanItemInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponsePlanItemInstanceResponse listPlanItemInstances(String id, String caseDefinitionId, String caseInstanceId, String stageInstanceId, String planItemDefinitionId, String planItemDefinitionType, String planItemDefinitionTypes, String state, String name, String elementId, String referenceId, String referenceType, String createdBefore, String createdAfter, String startUserId, String tenantId, Boolean withoutTenantId, String sort) throws RestClientException {
        Object postBody = null;

        String path = UriComponentsBuilder.fromPath("/cmmn-runtime/plan-item-instances").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "id", id));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "caseDefinitionId", caseDefinitionId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "caseInstanceId", caseInstanceId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "stageInstanceId", stageInstanceId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "planItemDefinitionId", planItemDefinitionId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "planItemDefinitionType", planItemDefinitionType));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "planItemDefinitionTypes", planItemDefinitionTypes));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "state", state));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "name", name));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "elementId", elementId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "referenceId", referenceId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "referenceType", referenceType));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "createdBefore", createdBefore));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "createdAfter", createdAfter));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "startUserId", startUserId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "tenantId", tenantId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "withoutTenantId", withoutTenantId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "sort", sort));

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponsePlanItemInstanceResponse> returnType = new ParameterizedTypeReference<DataResponsePlanItemInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Execute an action on a case instance
     *
     * <p><b>200</b> - Indicates the case instance was found and the action is performed.
     * <p><b>204</b> - Indicates the case was found, the action was performed and the action caused the case instance to end.
     * <p><b>400</b> - Indicates an illegal action was requested, required parameters are missing in the request body or illegal variables are passed in. Status description contains additional information about the error.
     * <p><b>404</b> - Indicates the case instance was not found.
     * @param caseInstanceId The caseInstanceId parameter
     * @param body The body parameter
     * @return CaseInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public CaseInstanceResponse performCaseInstanceAction(String caseInstanceId, RestActionRequest body) throws RestClientException {
        Object postBody = body;

        // verify the required parameter 'caseInstanceId' is set
        if (caseInstanceId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'caseInstanceId' when calling performCaseInstanceAction");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("caseInstanceId", caseInstanceId);
        String path = UriComponentsBuilder.fromPath("/cmmn-runtime/case-instances/{caseInstanceId}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<CaseInstanceResponse> returnType = new ParameterizedTypeReference<CaseInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.PUT, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Execute an action on a plan item instance
     *
     * <p><b>200</b> - Indicates the plan item instance was found and the action is performed.
     * <p><b>204</b> - Indicates the plan item instance was found, the action was performed and the action caused the plan item instance to end.
     * <p><b>400</b> - Indicates an illegal action was requested, required parameters are missing in the request body or illegal variables are passed in. Status description contains additional information about the error.
     * <p><b>404</b> - Indicates the plan item instance was not found.
     * @param planItemInstanceId The planItemInstanceId parameter
     * @param body The body parameter
     * @return PlanItemInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public PlanItemInstanceResponse performPlanItemInstanceAction(String planItemInstanceId, RestActionRequest body) throws RestClientException {
        Object postBody = body;

        // verify the required parameter 'planItemInstanceId' is set
        if (planItemInstanceId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'planItemInstanceId' when calling performPlanItemInstanceAction");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("planItemInstanceId", planItemInstanceId);
        String path = UriComponentsBuilder.fromPath("/cmmn-runtime/plan-item-instances/{planItemInstanceId}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<PlanItemInstanceResponse> returnType = new ParameterizedTypeReference<PlanItemInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.PUT, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Query plan item instances
     * The request body can contain all possible filters that can be used in the List plan item instances URL query. On top of these, it’s possible to provide an array of variables and caseInstanceVariables to include in the query, with their format described here.  The general paging and sorting query-parameters can be used for this URL.
     * <p><b>200</b> - Indicates request was successful and the plan item instances are returned.
     * <p><b>404</b> - Indicates a parameter was passed in the wrong format. The status message contains additional information.
     * @param body The body parameter
     * @return DataResponsePlanItemInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponsePlanItemInstanceResponse queryPlanItemInstances(PlanItemInstanceQueryRequest body) throws RestClientException {
        Object postBody = body;

        String path = UriComponentsBuilder.fromPath("/cmmn-query/plan-item-instances").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponsePlanItemInstanceResponse> returnType = new ParameterizedTypeReference<DataResponsePlanItemInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
}
